//
//  LKElearnCollectionViewCell.m
//  YLHelper
//
//  Created by she1323 on 2018/5/8.
//  Copyright © 2018年 she1323. All rights reserved.
//

#import "LKElearnCollectionViewCell.h"

@interface LKElearnCollectionViewCell()

@property (weak, nonatomic) IBOutlet UILabel *titleLabel;
@property (weak, nonatomic) IBOutlet UIButton *priseBtn;
@property (weak, nonatomic) IBOutlet UIButton *collectBtn;
@property (weak, nonatomic) IBOutlet UIImageView *recommadImg;

@property (weak, nonatomic) IBOutlet UIImageView *tuijianImageV;


@end

@implementation LKElearnCollectionViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    self.layer.borderColor = cellHeaderBgColor.CGColor;
    self.layer.borderWidth = 1;
    // Initialization code
}
-(void)setModel:(LKVideoModel *)model{
    _model = model;
    [self.priseBtn setTitle:[NSString stringWithFormat:@" %@",_model.praiseCount] forState:UIControlStateNormal];
    [self.collectBtn setTitle:[NSString stringWithFormat:@" %@",_model.collectionCount]  forState:UIControlStateNormal];
    [self.priseBtn setTitle:[NSString stringWithFormat:@" %@",_model.praiseCount] forState:UIControlStateSelected];
    [self.collectBtn setTitle:[NSString stringWithFormat:@" %@",_model.collectionCount]  forState:UIControlStateSelected];
    self.collectBtn.selected = [_model.isCollectioned boolValue];
    if ([_model.isRecommend integerValue]) {
        self.tuijianImageV.hidden = NO;
    }else{
        self.tuijianImageV.hidden = YES;
    }
    self.titleLabel.text = _model.videoName;
    [self.recommadImg sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",ServerlUrl,_model.coverImage]] placeholderImage:[UIImage imageNamed:@"pic"]];
}
- (IBAction)priseAction:(id)sender {
    UIButton *btn = (UIButton *)sender;
    btn.selected = !btn.selected;
    NSString *number;
    if (btn.selected) {
        number = @"1";
    }else{
        number = @"-1";
    }
    [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:VideoPriseUrl header:[LKUserInforTool header] parameters:@{@"Id":self.model.videoId,@"number":number} progress:^(NSProgress * _Nullable progress) {
        
    } success:^(BOOL isSuccess, id  _Nullable responseObject) {
        if ([number isEqual:@"1"]) {
            [btn setTitle:[NSString stringWithFormat:@" %ld",[self.model.praiseCount integerValue] + 1] forState:UIControlStateSelected];
            [SVProgressHUD showInfoWithStatus:@"点赞成功"];
        }else{
            btn.titleLabel.text = [NSString stringWithFormat:@" %ld",[self.model.praiseCount integerValue]];
            [SVProgressHUD showInfoWithStatus:@"取消点赞成功"];
        }

    } failure:^(NSString * _Nullable errorMessage) {
        
    }];
}
- (IBAction)collectAction:(id)sender {
    UIButton *btn = (UIButton *)sender;
    if (!btn.selected) {
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:VideoCollectUrl header:[LKUserInforTool header] parameters:@{@"Id":self.model.videoId} progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            
            [btn setTitle:[NSString stringWithFormat:@" %ld",[self.model.collectionCount integerValue] + 1] forState:UIControlStateSelected];
            [SVProgressHUD showInfoWithStatus:@"收藏成功"];
            
        } failure:^(NSString * _Nullable errorMessage) {
            
        }];
    }else{
        [[LKNetDataManager defaultManager] sendRequestMethod:HTTPMethodPOST serverUrl:ServerlUrl apiPath:videoCancelColleUrl header:[LKUserInforTool header] parameters:@{@"Id":self.model.videoId} progress:^(NSProgress * _Nullable progress) {
            
        } success:^(BOOL isSuccess, id  _Nullable responseObject) {
            btn.titleLabel.text = [NSString stringWithFormat:@" %ld",[self.model.collectionCount integerValue]];
            [SVProgressHUD showInfoWithStatus:@"取消收藏成功"];
        } failure:^(NSString * _Nullable errorMessage) {
            
        }];
    }

        btn.selected = !btn.selected;
}


@end
